package com.liujit.bms.app.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liujit.bms.app.domain.model.BlogCategory;
import com.liujit.bms.app.domain.query.BlogCategoryQuery;
import com.liujit.bms.app.domain.result.BlogCategoryResult;
import com.liujit.bms.app.mapper.BlogCategoryMapper;
import com.liujit.bms.app.service.BlogCategoryService;
import com.liujit.common.constants.GlobalConstant;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description 博客分类Service实现类
 * @Author liujun
 * @Date 2021-07-13 11:10:35
 */
@Service
public class BlogCategoryServiceImpl extends ServiceImpl<BlogCategoryMapper, BlogCategory> implements BlogCategoryService {

    @Override
    public List<BlogCategoryResult> getList(BlogCategoryQuery query) {
        query.setEnabled(GlobalConstant.ENABLED_YES);
        return super.baseMapper.selList(query);
    }

    @Override
    public String getNameById(Long categoryId) {
        LambdaQueryWrapper<BlogCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(BlogCategory::getName);
        wrapper.eq(BlogCategory::getId, categoryId);
        return super.getObj(wrapper, item -> Convert.toStr(item));
    }
}
